package com.example.demo.controller;

import com.example.demo.common.ServerResponse;
import com.example.demo.entity.User;
import com.example.demo.mapper.UserMapper;
import com.example.demo.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    IUserService iUserService;

    @GetMapping("/queryById")
    ServerResponse<User> queryById(String id){
        ServerResponse serverResponse=iUserService.queryById(id);
        return serverResponse;

    }
    @GetMapping("/queryAll")
    ServerResponse<List> queryAll(){
        ServerResponse serverResponse=iUserService.queryAll();
        return serverResponse;
    }
    @PostMapping("/add")
    ServerResponse<User> add(User user){
        ServerResponse serverResponse=iUserService.add(user);
        return serverResponse;
    }
    @PostMapping("/updateById")
    ServerResponse<User> updateById(User user){
        ServerResponse serverResponse=iUserService.updateById(user);
        return serverResponse;
    }
    @PostMapping("/delById")
    ServerResponse<String> delById(String id){
        ServerResponse serverResponse=iUserService.delById(id);
        return serverResponse;
    }

//    @PostMapping("/login.do")
//    public ServerResponse<User> login(String username, String password, HttpSession session){
//        ServerResponse serverResponse=iUserService.login(username,password);
//        if(serverResponse.isSucc())session.getAttribute(Cnst.CURRENT_USER,serverResponse.getData());
//        return serverResponse;
//    }
//    @PostMapping("/get_userinfo.do")
//    protected ServerResponse<User> getUserInfo(HttpSession session){
//        User loginUser =(User) session.getAttribute(Cnst.CURRENT_USER);
//        if(loginUser ==null){
//
//        }
//    }

}
